package edu.cicese.graphics;

import com.sun.java.swing.plaf.windows.WindowsBorders;
import edu.cicese.tm.Thumb;
import edu.cicese.tm.Thumb;

import javax.swing.border.LineBorder;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;

/**
 * Created by: Eduardo Quintana Contreras
 * Date: 9/03/11
 * Time: 12:21 PM
 */
public class DashBorder extends LineBorder {
	private BasicStroke dashStroke = new BasicStroke(4, BasicStroke.CAP_BUTT,
			BasicStroke.JOIN_BEVEL, 1, new float[]{5, 5}, 0);
	private BasicStroke addDeleteStroke = new BasicStroke(8, BasicStroke.CAP_BUTT,
			BasicStroke.JOIN_BEVEL);
	private BasicStroke normalStroke = new BasicStroke(2, BasicStroke.CAP_BUTT,
			BasicStroke.JOIN_BEVEL);
	private Color blueBorder = new Color(79, 129, 189), blueOver = new Color(79, 129, 189, 50),
			blueSelected = new Color(79, 129, 189, 150), colorGreen = new Color(0, 222, 34, 150),
			colorRed = new Color(255, 0, 0, 150);
	private Color color;
	private Thumb thumb;
	private boolean entered;

	public DashBorder(Color color, Thumb thumb, boolean entered) {
		super(color);
		this.color = color;
		this.thumb = thumb;
		this.entered = entered;
	}

	public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
		Graphics2D g2d = (Graphics2D)g;
		g2d.setStroke(addDeleteStroke);
		// Paint border
		if (thumb.isNew && !thumb.toDelete) {
			// Paint 'Add' layer
			g2d.setColor(colorGreen);
			this.lineColor = colorGreen;
			g2d.drawLine(77, 38, 77, 68);
			g2d.drawLine(62, 53, 73, 53);
			g2d.drawLine(81, 53, 92, 53);
			g2d.setStroke(dashStroke);
			super.paintBorder(c, g2d, x + 3, y + 1, width - 3, height - 1);
		}/* else */if (thumb.toDelete) {
			// Paint 'Delete' layer
			g2d.setColor(colorRed);
			this.lineColor = colorRed;
			g2d.drawLine(65, 65, 89, 41);
			g2d.drawLine(65, 41, 74, 50);
			g2d.drawLine(80, 56, 89, 65);
			g2d.setStroke(dashStroke);
			super.paintBorder(c, g2d, x + 3, y + 1, width - 3, height - 1);
		}
		g2d.setStroke(normalStroke);
//		if (FrameSpace.selectedTagThumb.equals(thumb) || FrameSpace.selectedThumb.equals(thumb)) {
		if (thumb.selected) {
			// Paint 'selected' color
			g2d.setColor(blueSelected);
			g2d.fillRect(2, 1, width - 3, height - 2);
			g2d.setColor(blueBorder);
			g2d.drawRect(2, 1, width - 3, height - 2);
		}
		else if (entered) {
			// Paint 'over' color
			g2d.setColor(blueOver);
			g2d.fillRect(2, 1, width - 3, height - 2);
			g2d.setColor(blueBorder);
			g2d.drawRect(2, 1, width - 3, height - 2);
		}
		else if (width == 80) {
			thumb.label.setBorder(new WindowsBorders.DashedBorder(Color.LIGHT_GRAY, 1));
		}
		g2d.dispose();
	}
}
